<%@ page language="java" contentType="text/html; charset=UTF-8"   pageEncoding="UTF-8"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!--  <meta http-equiv="pragma" content="no-cache">
 <meta http-equiv="cache-control" content="no-cache">
 <meta http-equiv="expires" content="0">  -->  
<!-- 头部 -->	
<%@ include file="./space_head1.jsp"%>
<!-- 导航 -->	
<%@ include file="./space_head2.jsp"%>

<script type="text/javascript" src="${jspath}/js/ajaxfileupload.js"></script>
<script type="text/javascript" src="${jspath}/js/share_opt.js"></script>

<style type="text/css">
	.zyzx_text01_a {
		background-color:lightgray;
		border-radius: 2px;
	}
</style>

  <script language="javascript">
   
/*   onPageClickFunction = function(pageNo, event){
		location.href = '/sumer/share/init/' + pageNo + '/2';
	};  */
	
  var showId = "${showId}";

 
	// 初始化点击分页按钮的方法
	onPageClickFunction = function(pageNo, event){
		search1(pageNo, $('.zyzx_text01_a').attr('id'));
	};

	$(document).ready(function(){
		//$("#paging_div").pagination('selectPage', 3);		
	});

	function search1(pageNo, tagId){
		location.href = '/sumer/share/initShare/' + pageNo + '/5' + (tagId != null ? '?tagId=' + tagId : '');
	}

	function share_del(id) {
		if (window.confirm('确定要删除分享吗？')) {
			$.post("/sumer/share/delSharedResource", {id: id}, function(result) {
				if(result.state == 1){
					alert('删除成功！');
					location.reload();
				}else {
					alert('删除失败！');
				}
			}, 'json');
		}
	}
	function addDownloadCnt(id){
	
		    $.ajax({
                    url: "/sumer/share/addDownloadCnt",
                    type: 'post',
                    async :false,
                    data: {"id": id},
                    success: function (data) {
                    	
                    	 location.reload();
                    	}
        
	});
	}
	 
	 var fileInfo = null;
	 /**是否是当前用户**/
	 <c:if test="${isMeData}"> 
			//成员删除
			function  uploadFiles ( ){
				$("#share_shadow").show();
			 	$("#share_add").show();
			}
			//成员删除
			function  canceluploadFiles ( ){
				$("#share_shadow").hide();
			 	$("#share_add").hide();
			}

				
			
			 function ajaxFileUpload(){   
				 
			      $("#loading").ajaxStart(function(){//开始上传文件时显示一个图片
			         $(this).show();
			     }).ajaxComplete(function(){//文件上传完成将图片隐藏起来
			         $(this).hide();
			     });
			      
			     $.ajaxFileUpload({
				        url:'${uploadURL}',//用于文件上传的服务器端请求地址
				      //  url:'http://space.zhuclass.com/drm/att/up?token=12qwaszxcvdfer34',
				        secureuri:false,//一般设置为false
				        fileElementId:'fileInput',//文件上传空间的id属性  <input type="file" id="file" name="file" />
				        dataType: 'json',//返回值类型 一般设置为json
				        success: function (data, status){  //服务器成功响应处理函数
				        	if(data.code != 1){
				        		alert('上传成功!');
				        		fileInfo = {fileName:data.filename, fileId:data.id, fileSize:data.flength, fileType:data.ftype};
				            } else{
				            	alert(data.msg);
				            }
				        },
				        error: function (data, status, e){//服务器响应失败处理函数	        
				            alert(e);
				        }
			     });
			     return false;
			 }
			
				function save_share_file() {
					if(fileInfo == null){
						alert('请先上传文件！');
					}else{
						fileInfo.topic = $('#topic').val();
						fileInfo.tagId = $('#tagId').val();
						fileInfo.needIntegral = $('#needIntegral').val();
						var result = add_share_resource(fileInfo);
						if(result.state == 1){
							$('#topic').val("");
							$('#tagId').val("");
							$('#needIntegral').val("0");
							$('#fileInput').val("");
							alert('保存成功！');
							location.reload();
						} else {
							alert('保存失败！');
						}
					}
				}
				
				 </c:if> 

				 
	
	 function edit_share(shareId){
			$.post("/sumer/share/getSharedResourceById", {id: shareId}, function(result) {
				if(result.state == 1){
					
					 document.getElementById("shareId_edit").value=shareId;
					 document.getElementById("topic_edit").value=result.topic;
					 document.getElementById("needIntegral_edit").value=result.needIntegral;
					$("#share_shadow").show();
					 $("#share_edit").show();
				}else {
					alert('获取共享资源失败！');
				}
			}, 'json');
	 }
	 function editShare(shareId){
		 var id=$('#shareId_edit').val();
		 var topic_edit=$('#topic_edit').val();
		 var tagId_edit=$('#tagId_edit').val();
		 var needIntegral_edit=$('#needIntegral_edit').val();
		 $.post("/sumer/share/UpdateSharedResourceById", {id: id,topic:topic_edit,tag_id:tagId_edit,needIntegral: needIntegral_edit}, function(result) {
				if(result.state == 1){
					alert('修改成功！');
					location.reload();
					$("#share_shadow").hide();
					 $("#share_edit").hide();
					
				}else {
					alert('修改失败！');
					$("#share_shadow").hide();
					 $("#share_edit").hide();
				}
			}, 'json');
	 }
	 
	 function cancelEdit(){
		 $("#share_shadow").hide();
		 $("#share_edit").hide();
	 }
	
</script>

  <div class="zyt_body" style="height:auto;"> 
 
	
	<!--end导航-->
	<div class="user_body01" style="background-color:#FFFFFF;top:0px;">
		<div class="zyzx_more_div">
			<div class="zyzx_more_divt">
				<div class="zyzx_more_left">
					<div class="kczx_son_divbodytbl">
						<div id="tab1" class="user_tab1">
							<c:forEach items="${pageData.data}" var="share">
							<div class="zyzx_more_zt01">
								<table class="zyzx_more_tab01" >
									<tr>
										<td height="15px" width="600px"> </td>
									</tr>
									<tr>
										<td height="25px" style="font-size: 14px; font-weight: bold;">
										<a href="http://www.zhuclass.com/resource/detail/${share.id}">
										<c:choose>
											<c:when test="${share.fileType=='WORD'}"><img src="${imgpath}/images/zyzx_images/word.png"></c:when>
											<c:when test="${share.fileType=='PDF'}"><img src="${imgpath}/images/zyzx_images/pdficon.png"></c:when>
											<c:when test="${share.fileType=='RAR'}"><img src="${imgpath}/images/zyzx_images/xiazai01.jpg"></c:when>
											<c:when test="${share.fileType=='TEXT'}"></c:when>
											<c:otherwise></c:otherwise>
										</c:choose>													
										${share.topic}
										</a> </td>
										<%-- --%>
										<td rowspan="3"> <a href="${ downloadURL}${share.fileId}?fnm=${share.fileName} " onclick="addDownloadCnt('${share.id}');" target="block">
										<div class="share_xz01" style="background-color:#F39C4F;">
											<div class="share_xz02"> ${share.downCnt} </div>
											下&nbsp;载 </div>
										</a> </td>
									</tr>
									<tr>
										<td height="25px" style="color:#888;"> 大小：<fmt:formatNumber value="${share.fileSize/1024/1024}" pattern="##.##" minFractionDigits="2" ></fmt:formatNumber>M
											&nbsp;&nbsp;&nbsp;&nbsp; <span style="color:#333;"> 标签：</span>${share.tagName} </td>
									</tr>
									<tr>
										<td height="25px"> 上传于 ${share.createTime}&nbsp;&nbsp;
											&nbsp;&nbsp;&nbsp;&nbsp; <a href="#"> <img src="${imgpath}/images/zyzx_images/ping.png"/> 评论${share.commentCnt} </a> &nbsp;&nbsp;&nbsp;&nbsp;  <a href="#"> <img src="${imgpath}/images/zyzx_images/liu.png"/> 点击${share.viewCnt} </a> &nbsp;&nbsp;&nbsp;&nbsp; <c:if test="${isMeData}"><a href="javascript:edit_share('${share.id}');"> 编辑 </a>&nbsp; <a href="#" onclick="share_del('${share.id}');"> 删除 </a></c:if> </td>
									</tr>
								</table>
							</div>
							</c:forEach>
							
							<div class="tab500"></div>
							<div style="position:relative;float:left;width:99%;height:30px;">
								<%@ include file="../paging_form.jsp"%>
							</div>
					</div>
				</div>

				<div class="zyzx_more_right">
					<div class="zyzx_more_divlt" style="height:20px;"></div>
					<div class="zyzx_more_divlt">
						<table width="220px" height="80px" style="text-align:right;">
							<tr width="220px">
								<td width="110px"> </td>
								<td height="100px" valign="top" class="zyzx_text01" style="line-height:20px;text-align:right;"> 
								<!-- 是当前所属人员 -->
								 	<c:if test="${isMeData}"> 
										<a href="javascript:uploadFiles();">
										<div style="width:90px;height:25px;background-color:#578429;line-height:25px;text-align:center;color:#FFF;">
											 
											<img src="${imgpath}/images/add02.png"/> &nbsp;上传文件 </div>
										</a> 
									</c:if>
								</td>
							</tr>
						</table>
					</div>
				</div>
				<div class="zyzx_more_right">
					<div class="zyzx_more_divlt">
						<table width="220px" height="150px" cellspacing="0" cellpadding="0" >
							<tr width="220px" >
								<td height="20px" width="180px" class="retext02" style="color:#578429;font-weight:bold;border-bottom:1px solid #DDD;" >数据统计 </td>
							</tr>
							<tr width="220px">
								<td height="130px" valign="top" colspan="2" class="zyzx_text01" style="line-height:20px;"> <a href="#">上传文件数：${pageData.totalCount}</a><br/>
									<!-- <a href="#">下载文件数：10</a><br/> -->
								</td>
							</tr>
						</table>
					</div>
				</div>
				<div class="zyzx_more_right">
					<div class="zyzx_more_divlt">
						<table width="220px" height="180px" cellspacing="0" cellpadding="0">
							<tr width="220px">
								<td height="20px" width="180px" class="retext02" style="color:#578429;font-weight:bold;border-bottom:1px solid #DDD;" >热门标签 </td>
								<!-- <td style="border-bottom:1px solid #DDD;"> <a href="#"> 管理 </a> </td> -->
							</tr>
							<tr width="220px">
								<td height="130px" valign="top" colspan="2"  class="zyzx_text01" style="line-height:20px;">
									<c:forEach items="${hostTag}" var="tag">
										<a href="#" id="${tag.id}" <c:if test="${tagId==tag.id}">class="zyzx_text01_a"</c:if> onclick="search1(0, '${tag.id}');">${tag.name}</a>&nbsp;&nbsp;
									</c:forEach>
								</td>
							</tr>
						</table>
					</div>
				</div>
			</div>
		</div>
	</div>
</div>
 
 <!--start新增上传资源-->
<div id="share_add" style="display: none;left: 35%; position: fixed;z-index:33; top: 30%; width: 400px; background-color: rgb(255, 255, 255); border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">
	<div class="collect_add01" style="padding-bottom:5px">标签：
		<select id="tagId" style="height:25px;width:80px;font-size:12px;padding:0;margin:0;">		
			<c:forEach items="${tagList}" var="tag">
			<option value="${tag.id}"> ${tag.name} </option>
			</c:forEach>
		</select>
	</div>
	<div class="collect_add02" style="text-align:left;left:30px;height:40px"> 使用积分：
		<input id="needIntegral" type="text" style="height:25px;" value="0">
	</div>	
	<div class="collect_add02" style="text-align:left;left:30px;height:40px"> 资源名称：
		<input id="topic" type="text" style="height:25px;" value="0">
	</div>
		<div class="collect_add02"
			style="text-align: left; left: 30px; height: 40px">
			资&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;源： <input id="source"
				type="text" style="height: 25px;" value="" disabled > <input
				type="file" id="fileInput" name="upload" accept="file"    onchange="$('#source').val(this.value)" 
				style="position: absolute; opacity: 0; width: 40px; height: 25px;">
			<button
				style="background-color: #578429; color: #FFFFFF; height: 25px">浏览</button>
			<button onclick="ajaxFileUpload();"
				style="background-color: #578429; color: #FFFFFF; height: 25px">上传文件</button>
		</div>

		<div class="collect_add02"> <a href="#">
		<div style="height:24px;width:50px; background-color:#578429;color:#FFF;position:absolute;float:left;left:120px;" onclick="save_share_file();"> 确&nbsp;认 </div>
		</a> <a href="#" onmousedown="canceluploadFiles()">
		<div style="height:24px;width:50px;color:#555;position:absolute;float:left;left:180px;"> 取&nbsp;消 </div>
		</a> </div>
</div>
<div id="share_shadow" style="display: none;position: fixed; left: 0%; top: 0; width: 100%;height:100%; background-color: rgba(0, 0,0,.3);z-index:1"></div>
<!--end新建收藏夹-->
 <div id="share_edit" style="display: none;left: 35%; position: fixed;z-index:33; top: 30%; width: 400px; background-color: rgb(255, 255, 255); border: 1px solid rgb(221, 221, 221); border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px;">
	<div class="collect_add01" style="padding-bottom:5px">标签：
		<select id="tagId_edit" style="height:25px;width:80px;font-size:12px;padding:0;margin:0;">		
			<c:forEach items="${tagList}" var="tag">
			<option value="${tag.id}"> ${tag.name} </option>
			</c:forEach>
		</select>
	</div>
	
		<input id="shareId_edit" hidden="true" type="text" style="height:25px;" value="0">

	<div class="collect_add02" style="text-align:left;left:30px;height:40px"> 使用积分：
		<input id="needIntegral_edit" type="text" style="height:25px;" value="0">
	</div>	
	<div class="collect_add02" style="text-align:left;left:30px;height:40px"> 资源名称：
		<input id="topic_edit" type="text" style="height:25px;" value="0">
	</div>
	<div class="collect_add02"> <a href="#">
		<div style="height:24px;width:50px; background-color:#578429;color:#FFF;position:absolute;float:left;left:120px;" onclick="editShare( document.getElementById('shareId_edit').value);"> 确&nbsp;认 </div>
		</a> <a href="#" onmousedown="cancelEdit()">
		<div style="height:24px;width:50px;color:#555;position:absolute;float:left;left:180px; onclick="cancelEdit()"> 取&nbsp;消 </div>
		</a></div>
	</div>
 
 <!--  结尾 -->
 <%@ include file="../all_buttom.jsp"%>
</body> 

</html>